package com.ymttest.business.service.shenqi;

import java.io.IOException;
import java.math.BigDecimal;
import java.util.Arrays;

import org.apache.http.client.ClientProtocolException;

import com.shop2cn.iapi.pretrade.paremeter.ChargeReq;
import com.shop2cn.iapi.pretrade.paremeter.MultiDeliveryReq;
import com.shop2cn.iapi.pretrade.paremeter.OnFinishReq;
import com.shop2cn.iapi.pretrade.paremeter.pojo.DeliveryPkgVo;
import com.shop2cn.iapi.pretrade.paremeter.pojo.DeliverySegmentVo;
import com.shop2cn.iapi.pretrade.service.ChargeCall;
import com.shop2cn.iapi.pretrade.service.MultiDeliveryCall;
import com.shop2cn.iapi.pretrade.service.OnFinishCall;
import com.ymttest.utils.TestDataManager;

public class SqPretradeService {

	public static void onFinish(Long activityId) throws ClientProtocolException, IOException {
		
		OnFinishReq onFinishReq = new OnFinishReq();
		OnFinishCall onFinishCall = new OnFinishCall();
		
		onFinishReq.setActivityId(activityId);

		// 发送请求
		onFinishCall.setData(onFinishReq);
		onFinishCall.callService();
	}
	
	/**
	 * 神器多段发货
	 * @throws IOException 
	 * @throws ClientProtocolException 
	 */
	public static String multiDelivery(long goodsOwnerId, long orderId)
			throws ClientProtocolException, IOException {

		MultiDeliveryReq multiDeliveryReq = new MultiDeliveryReq();
		MultiDeliveryCall multiDeliveryCall = new MultiDeliveryCall();

		// 物流单号
		String deliverSummary = TestDataManager.randomStr(10);

		DeliverySegmentVo deliverySegmentVo = new DeliverySegmentVo();

		deliverySegmentVo.setBillNo(deliverSummary);
		deliverySegmentVo.setExpressName("自动化测试物流");
		deliverySegmentVo.setMobile(TestDataManager.getPhoneNum());
		deliverySegmentVo.setYmtExpressCode("Y022");

		DeliveryPkgVo deliveryPkgVo = new DeliveryPkgVo();

		deliveryPkgVo.setSegments(Arrays.asList(deliverySegmentVo));

		multiDeliveryReq.setPackages(Arrays.asList(deliveryPkgVo));

		multiDeliveryReq.setCdId(1234L);
		multiDeliveryReq.setGoodsOwnerId(goodsOwnerId);
		multiDeliveryReq.setDeliverySource(11);
		multiDeliveryReq.setOrderId(orderId);

		multiDeliveryCall.setData(multiDeliveryReq);
		multiDeliveryCall.callService();

		return deliverSummary;
	}

	/**
	 * 代币充值
	 * 
	 * @throws IOException
	 * @throws ClientProtocolException
	 */
	public static void virtualCoinCharge(Long virtualCoinGoodsOwnerId,
			Long agencyId, BigDecimal amount) throws ClientProtocolException,
			IOException {

		ChargeReq chargeReq = new ChargeReq();
		ChargeCall chargeCall = new ChargeCall();

		chargeReq.setGoodsOwnerId(virtualCoinGoodsOwnerId);
		chargeReq.setAgencyId(agencyId);
		chargeReq.setAmount(amount);
		chargeReq.setCsId(virtualCoinGoodsOwnerId);
		chargeReq.setMemo("充值");
		chargeReq.setOperator("operato");
		chargeReq.setUniqueCode(TestDataManager.getRandomUUID().toString());

		// 发送请求
		chargeCall.setData(chargeReq);
		chargeCall.callService();
	}
}
